package com.neuedu.hostp.dao;

import com.neuedu.hostp.entity.Checkin;


import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@CacheNamespace
@Mapper
public interface CheckinMapper {
    @Delete({
        "delete from check_in",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into check_in (id, customer_id, ",
        "check_in_time, check_out_time, ",
        "bed_id)",
        "values (#{id,jdbcType=INTEGER}, #{customerId,jdbcType=INTEGER}, ",
        "#{checkInTime,jdbcType=TIMESTAMP}, #{checkOutTime,jdbcType=VARCHAR}, ",
        "#{bedId,jdbcType=INTEGER})"
    })
    int insert(Checkin record);
    
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    @InsertProvider(type=CheckinSqlProvider.class, method="insertSelective")
    int insertSelective(Checkin record);

    @Select({
        "select",
        "id, customer_id, check_in_time, check_out_time, bed_id",
        "from check_in",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.INTEGER),
        @Result(column="check_in_time", property="checkInTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="check_out_time", property="checkOutTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="bed_id", property="bedId", jdbcType=JdbcType.INTEGER)
    })
    Checkin selectByPrimaryKey(Integer id);
    
    @Select({
        "select",
        "id, customer_id, check_in_time, check_out_time, bed_id",
        "from check_in",
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.INTEGER),
        @Result(column="check_in_time", property="checkInTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="check_out_time", property="checkOutTime", jdbcType=JdbcType.VARCHAR),
        @Result(column="bed_id", property="bedId", jdbcType=JdbcType.INTEGER)
    })
    List<Checkin> selectAll();

    @UpdateProvider(type=CheckinSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Checkin record);

    @Update({
        "update check_in",
        "set customer_id = #{customerId,jdbcType=INTEGER},",
          "check_in_time = #{checkInTime,jdbcType=TIMESTAMP},",
          "check_out_time = #{checkOutTime,jdbcType=VARCHAR},",
          "bed_id = #{bedId,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Checkin record);
}